package com.bs.modules.wechat.controller;

import com.bs.common.utils.R;
import com.bs.modules.use.service.OrderService;
import com.bs.modules.wechat.vo.VxOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @作者 ：lichenguang
 * @描述 ：【订单编号】
 * @创建 ：2022/4/8 20:59
 */
@RestController
@RequestMapping("wechat/order")
@Api(tags = "wechat用户信息")
@Slf4j
public class OrderController {

  @Autowired
  private OrderService orderService;

  @SneakyThrows
  @ApiOperation(value = "微信绑定用户编号")
  @GetMapping("/findOrder")
  public R bingUserId(@RequestParam Map<String, Object> params) {
    Object openid = params.get("openid");
    if (openid == null || "".equals(openid)) {
      return R.error("请先登录");
    }

    Object status = params.get("status");
    if (status == null || "".equals(status)) {
      return R.error("状态不能为空");
    }

    List<VxOrderVo> list = orderService.orderHistory(openid, status);

    return R.ok().put("data", list);
  }


  @SneakyThrows
  @ApiOperation(value = "微信绑定用户编号")
  @PostMapping("/pay")
  public R pay(@RequestBody Map<String, Object> params) {

    log.info("参数：{}", params);
    orderService.pay(params.get("type"), params.get("orderId"), params.get("payMoney"));

    //....
    return R.ok();
  }
}
